
// HighSpeedCaptureDlg.h : header file
//

#pragma once

// CHighSpeedCaptureDlg dialog
class CHighSpeedCaptureDlg : public CDialogEx, public DShowLib::FrameQueueSinkListener
{
// Construction
public:
	CHighSpeedCaptureDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_HIGHSPEEDCAPTURE_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	CSize m_minSize;

	DShowLib::Grabber m_Grabber;
	smart_ptr<DShowLib::FrameQueueSink> m_pSink;

	struct SinkStats
	{
		size_t numFreeBuffers;
		size_t numFilledBuffers;
		size_t numProcessingBuffers;		

		size_t bufferSize;

		size_t numProcessed;
	};

	SinkStats m_sinkStats;
	int m_frameNumber;

	void UpdateStatsUI( const SinkStats& stats );

	void UpdateStats( DShowLib::FrameQueueSink& sink, SinkStats& stats, size_t numProcessingBuffers, size_t addProcessed );

	void ResizeLiveVideo();

	void TryAllocateBuffers( int bufferMemoryMiB );

	// Generated message map functions
	virtual BOOL OnInitDialog();
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnGetMinMaxInfo( MINMAXINFO* lpMMI );
	afx_msg void OnBnClickedDestinationBrowse();	
	afx_msg void OnSize( UINT nType, int cx, int cy );
	afx_msg void OnBnClickedDevice();
	afx_msg void OnBnClickedStartStop();
	afx_msg void OnClose();
	afx_msg LRESULT OnUpdateStatsUI( WPARAM wParam, LPARAM lParam );

public:
	// Inherited via FrameQueueSinkListener
	virtual void sinkConnected( DShowLib::FrameQueueSink& sink, const DShowLib::FrameTypeInfo& frameType );
	virtual void sinkDisconnected( DShowLib::FrameQueueSink& sink );
	virtual void framesQueued( DShowLib::FrameQueueSink& sink );

private:
	CString m_destinationFolder;
	int m_bufferMemoryMiB;
	CButton m_btnStartStop;	
	CButton m_btnBufferMaximize;
	CButton m_btnDestinationBrowse;
	CProgressCtrl m_progressFreeBuffers;
	CProgressCtrl m_progressFilledBuffers;
	CStatic m_lblFreeBuffers;
	CStatic m_lblFilledBuffers;		
	CStatic m_lblCaptureInfo;
public:	
	virtual BOOL PreTranslateMessage( MSG* pMsg );
	afx_msg void OnKillfocusEditBufferMemory();
	afx_msg void OnBnClickedBufferMaximize();	
	afx_msg void OnTimer( UINT_PTR nIDEvent );
};
